﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using BLL;
public partial class MemberInfo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.InitParm();
        }
    }

    private void InitParm()
    { 
       MembersBll bll=new MembersBll();
       Members mb = bll.SelectMember(HttpMemberInfo.MemerID);

       if (mb == null)
       {
           Response.Redirect("~/login.aspx");
       }

       this.txtCity.Text = mb.City;
       this.txtBirthDay.Text = mb.Birthday.ToString();
       this.txtEmail.Text = mb.EMail;
       this.txtRealName.Text = mb.RealName;
    }

    protected void btnMember_Click(object sender, EventArgs e)
    { 
        MembersBll bll = new MembersBll();
        Members mb = bll.SelectMember(HttpMemberInfo.MemerID);

        Button btn = sender as Button;

        if (btn.CommandName == "Pwd")
        {
            if (this.txtOldPwd.Text != mb.PassWord)
            {
                Library.WebCommon.Alert(this, "密码错误，请重新输入");
                hdnType.Value = "1";
                return;
            }

            mb.PassWord =Common.MD5(this.txtPwd.Text.Trim()+MembersBll.Sold);
        }
        else
        {
            mb.RealName = this.txtRealName.Text.Trim();
            mb.EMail = this.txtEmail.Text.Trim();
            mb.City = this.txtCity.Text.Trim();
            if (this.txtBirthDay.Text.Trim() != "")
            {
                mb.Birthday = DateTime.Parse(this.txtBirthDay.Text);
            }

            hdnType.Value = "2";
        }

        bool isOk=bll.UpdateMembers(mb);
        if (!isOk)
        {
            Library.WebCommon.Alert(this, "修改失败");
            return;
        }
        Library.WebCommon.Alert(this, "修改成功");
    }
}
